<template>
    <div>
        <h3>房价计划修改</h3>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>房价计划名称</td>
                    <td>
                        <input type="text" v-model="queryadd.HousePriceName">
                    </td>
                </tr>
                <tr>
                    <td>门店</td>
                    <td>
                        <td>
                        <select v-model="queryadd.ShopId">
                            <option value="">请选择</option>
                            <option :value="item.Id" v-for="item in shop.list">{{item.ShopName}}</option>
                        </select>
                    </td>
                    </td>
                </tr>
                <tr>
                    <td>房型</td>
                    <td>
                        <select v-model="queryadd.HouseTypeId">
                            <option value="">请选择</option>
                            <option :value="item.Id" v-for="item in house.list">{{item.HouseTypeName}}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>房型价格</td>
                    <td>
                        <input type="text" v-model="queryadd.Price">
                    </td>
                </tr>
                <tr>
                    <td>数量</td>
                    <td>
                        <input type="text" v-model="queryadd.Count">
                    </td>
                </tr>
                <tr>
                    <td>状态</td>
                    <td>
                        <input type="radio" :value="1" class="state" v-model="queryadd.State">开启
                        <input type="radio" :value="0" class="state" v-model="queryadd.State">禁用
                    </td>
                </tr>
                <tr>
                    <td>早餐数量</td>
                    <td>
                        <input type="text" v-model="queryadd.BreakFastCount">
                    </td>
                </tr>
                <tr>
                    <td>开始时间</td>
                    <td>
                        <input type="date" v-model="queryadd.BeginTime">
                    </td>
                </tr>
                <tr>
                    <td>结束时间</td>
                    <td>
                        <input type="date" v-model="queryadd.EndTime" >
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="修改" class="btn btn-primary" @click="ok">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import{ref,reactive,onMounted} from 'vue'
import {useRouter,useRoute} from 'vue-router'
import axios from 'axios';
import moment from 'moment';

import { useUserStore } from '@/stores/user';
const UserStore=useUserStore();
const router=useRouter();
const route=useRoute();

onMounted(()=>{
    showshop();
    showHouse();
    fantian();
})

const fantian=()=>{
    axios({
        method:'get',
        url:'/api/House/HousePricePlanGets',
        params:{id:route.query.id},
    })
    .then(res=>{
        console.log(res);
        Object.assign(queryadd,res.data);
        queryadd.BeginTime=res.data.BeginTime.substring(0,10)
        queryadd.EndTime=res.data.EndTime.substring(0,10)
    })
    .catch(err=>{
        console.log(err);
    })
}


const queryadd=reactive({
   "Id": route.query.id,
  "HousePriceName": "",
  "ShopId": '',
  "HouseTypeId": '',
  "Price": '',
  "Count": '',
  "State": '',
  "BreakFastCount": '',
  "BeginTime": "",
  "EndTime": "",
})
const ok=()=>{

    

    axios({
        method:'put',
        url:'/api/House/HousePricePlanUpd',
        data:queryadd,
    })
    .then(res=>{
        console.log(res);

        if(res.data>0){
            alert("修改成功");

        }
        else{
            alert("修改失败")
        }
    })
    .catch(err=>{
        console.log(err);
    })
}

const shop:any=reactive({
    list:[],
})
const showshop=()=>{
    axios({
        method:'get',
        url:'/api/Shop/GetShopList',
        params:{
            pageIndex:1,
            pageSize:1000,
        }
    })
    .then(res=>{
        console.log(res);
        shop.list=res.data.list     
    })
    .catch(err=>{
        console.log(err);
    })
}
const house:any=reactive({
    list:[],
})
const showHouse=()=>{
    axios({
        method:'get',
        url:'/api/House/GetHouseTypeList',
        params:{
            pageIndex:1,
            pageSize:1000,
        }   
    })
    .then(res=>{
        console.log(res);
        house.list=res.data.list
       
    })
    .catch(err=>{
        console.log(err);
    })
}


</script>

<style scoped>

</style>